<?php
/**
 * Created by PhpStorm.
 * 商家银行卡
 * User: caicm
 * Date: 2017/6/28
 * Time: 15:44
 */

namespace WMApi\Model;


use Think\Model;

class WmSellerBankCardModel extends Model {

    /**
     * 添加银行卡
     * Created By caicm
     * @param int $seller_id 商家id
     * @param string $bank_card_account 银行卡开户人
     * @param string $bank_card_number 银行卡号
     * @param string $bank_card_dbk 银行卡所属银行
     * @param string $bank_card_subbranch 银行卡支行
     * @param array $address_data 地址信息
     * @return mixed
     */
    public function add_bank_card( $seller_id=0, $bank_card_account='', $bank_card_number='', $bank_card_dbk='', $bank_card_subbranch='', $address_data=array()){

        $data = array(
            'seller_id' => $seller_id,
            'bank_card_account' => $bank_card_account,
            'bank_card_number' => $bank_card_number,
            'bank_card_dbk' => $bank_card_dbk,
            'bank_card_subbranch' => $bank_card_subbranch,
            'bank_card_province_id' => $address_data['province'],
            'bank_card_province_name' => $address_data['province_name'],
            'bank_card_city_id' => $address_data['city'],
            'bank_card_city_name' => $address_data['city_name'],
            'bank_card_district_id' => $address_data['district'],
            'bank_card_district_name' => $address_data['district_name'],
            'add_time' => gmtime()
        );

        return $this->data($data)->add();

    }

    /**
     * 获取商家银行卡列表
     * Created By caicm
     * @param int $seller_id
     * @return mixed
     */
    public function find_bank_card_list($seller_id=0){

        $where = array(
            'seller_id' => $seller_id
        );

        return $this->where($where)->order('bank_card_id desc')->select();

    }

    /**
     * 获取商家银行卡详情
     * Created By caicm
     * @param int $seller_id
     * @param int $bank_card_id
     * @return mixed
     */
    public function find_bank_card_info($seller_id=0, $bank_card_id=0){

        $where = array(
            'seller_id' => $seller_id,
            'bank_card_id' => $bank_card_id
        );

        return $this->where($where)->find();

    }

    /**
     * 获取商家银行卡数量
     * Created By caicm
     * @param int $seller_id
     * @return mixed
     */
    public function find_bank_card_count($seller_id=0){

        $where = array(
            'seller_id' => $seller_id
        );

        return $this->where($where)->count();

    }


}